<html>
<head>


    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctx}/wangEditor/3.1.1/wangEditor.min.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet">


    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/layui/lay/modules/laydate.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-switch/js/bootstrap-switch.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/wangEditor/10.0.13/wangEditor.min.js"></script>

    <script src="${ctx}/js/iw.js"></script>



    <style>
        .btn {
            font-size: 12px;
        }

        .lay-box {
            padding: 10px;
        }
    </style>
</head>
<body>

<form class="layui-form" action="" lay-filter="item" style="width: 100%;margin-top: 10px;">
    <input type="hidden" name="id" readonly value="${item.id!''}">
    <input type="hidden" name="taskId" readonly value="${item.taskId!''}">

    <div class="layui-form-item" style="width: 100%;" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>计算奖励(分)</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="worth"
                   lay-verify="required" placeholder="请输入单价(单位:分)"
                   autocomplete="off" class="layui-input" value="${item.worth!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>商务结算单价(单位:分)</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="increase"
                   lay-verify="required" placeholder="请输入收益(单位:分)"
                   autocomplete="off" class="layui-input" value="${item.increase!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>客户单价</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="bussAmount"
                   lay-verify="required" placeholder="客户单价(单位:分)"
                   autocomplete="off" class="layui-input" value="${item.bussAmount!''}">
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>任务标题</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="title"
                   lay-verify="required" placeholder="请输入任务标题"
                   autocomplete="off" class="layui-input" value="${item.title!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>图标</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="icon"
                   lay-verify="required" placeholder="请输入图标"
                   autocomplete="off" class="layui-input" value="${item.icon!''}">
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <div class="form-group">
            <label for="size" class="control-label pr_no" style="width: 25%;float: left;text-align: right;padding: 9px 15px;">奖励类型</label>
            <div style="width: 70%;float: left;">
                <select class="form-control" id="type" name="type">
                    <#list types as type>
                        <option value="${type}" <#if item?? && item.type == type>selected</#if>>${type.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%">屏蔽渠道</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="brand"
                   placeholder="请输入屏蔽渠道"
                   autocomplete="off" class="layui-input" value="${item.brand!'all'}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>客户</label>
        <div style="width: 70%;float: left;">
            <select id="customer" name="customer" style="height: 34px;width:100%;border-radius: 4px;border-color: #ccc;>
                <option value="zy">自营</option>
            <#if customlist?? && ((customlist?size)>0)>
                <#list customlist as list>
                        <option value="${list.customId}" <#if item.customer?? && list.customId == item.customer>selected</#if> >${list.name}</option>
                </#list>
            </#if>
            </select>
        </div>

    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>每日量</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="amount"
                   lay-verify="required" placeholder="请输入每日量"
                   autocomplete="off" class="layui-input" value="${item.amount!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>总量</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="total"
                   lay-verify="required" placeholder="请输入总量"
                   autocomplete="off" class="layui-input" value="${item.total!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>任务预计耗时(分钟)</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="taskTime"
                   lay-verify="required" placeholder="请输入任务预计耗时(分钟)"
                   autocomplete="off" class="layui-input" value="${item.taskTime!'5'}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>承诺审核时间(分钟)</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="auditTime"
                   lay-verify="required" placeholder="请输入承诺审核时间(分钟)"
                   autocomplete="off" class="layui-input" value="${item.auditTime!'1440'}">
        </div>
    </div>



    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>达到领取上限后需等待(分钟)</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="waitTime"
                   lay-verify="required" placeholder="达到领取上限后需等待(分钟)"
                   autocomplete="off" class="layui-input" value="${item.waitTime!0}">
        </div>
    </div>


    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>领取触发隐藏任务的次数</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="waitCount"
                   lay-verify="required" placeholder="领取触发隐藏任务的次数"
                   autocomplete="off" class="layui-input" value="${item.waitCount!0}">
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>完成后等待时长（小时）</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="lessTime"
                   lay-verify="required" placeholder="完成后等待时长（单位:小时）"
                   autocomplete="off" class="layui-input" value="${item.lessTime!0}">
        </div>
    </div>




    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%">任务要求</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="mission"
                   placeholder="任务要求"
                   autocomplete="off" class="layui-input" value="${item.mission!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>是否可重做</label>
        <div class="layui-input-block">

            <#if item.redo gt 0 && item.redo??>
                <input type="radio" name="redo" value=1 title="是" checked >
                <input type="radio" name="redo" value=0 title="否"  >
            <#elseif item.redo == 0 && item.redo??>
                <input type="radio" name="redo" value=1 title="是">
                <input type="radio" name="redo" value=0 title="否" checked >
            <#else >
                <input type="radio" name="redo" value=1 title="是" checked>
                <input type="radio" name="redo" value=0 title="否"  >
            </#if>
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>排序</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="number" name="sort"
                   lay-verify="required" placeholder="请输入排序"
                   autocomplete="off" class="layui-input" value="${item.sort!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%"><span class="c-red">*</span>副标题</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="label"
                   lay-verify="required" placeholder="请输入副标题"
                   autocomplete="off" class="layui-input" value="${item.label!''}">
        </div>
    </div>


    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%">教程</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="media"
                   placeholder="请输入教程"
                   autocomplete="off" class="layui-input" value="${item.media!''}">
        </div>
    </div>
    <textarea name="contents" type="hidden" style="display: none"></textarea>
    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%">前置条件</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="pkg"
                   placeholder="请输入前置条件"
                   autocomplete="off" class="layui-input" value="${item.pkg!''}">
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <div class="form-group">
            <label for="size" class="control-label pr_no" style="width: 25%;float: left;text-align: right;padding: 9px 15px;">任务状态</label>
            <div style="width: 70%;float: left;margin-left:initial;">
                <select class="form-control" id="status" name="status">
                    <option value="1" <#if item?? && item.status == 1>selected</#if>>上架</option>
                    <option value="0" <#if item?? && item.status == 0>selected</#if>>下架</option>
                    <option value="2" <#if item?? && item.status == 2 >selected</#if>>待上架</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <div class="form-group">
            <label for="icon" class="control-label pr_no" style="width: 25%;float:left;text-align: right;padding: 9px 15px;">任务自动上架时间</label>
            <div style="width: 70%;float: left;margin-left:initial;">
                <input type="text" class="form-control" id="autoTime" autocomplete="off" name="autoTime" placeholder="不填写标识没有开启" value="<#if item??>${item.autoTime!''}</#if>">
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <div class="form-group">
            <label for="icon" class="control-label pr_no" style="width: 25%;float:left;text-align: right;padding: 9px 15px;">任务自动下架时间</label>
            <div style="width: 70%;float: left;margin-left:initial;">
                <input type="text" class="form-control" id="autoOffTime" autocomplete="off" name="autoOffTime" placeholder="不填写标识没有开启" value="<#if item??>${item.autoOffTime!''}</#if>">
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="width: 100%;">
        <div class="form-group" >
            <label for="icon" class="control-label pr_no" style="width: 25%;float:left;text-align: right;padding: 9px 15px;">用户最小金额限制(分)</label>
            <div style="width: 70%;float: left;margin-left:initial;">
                <input type="text" class="form-control" id="minMoney" name="minMoney" placeholder="0为没有金额限制" value="<#if item??>${item.minMoney!''}</#if>">
            </div>
        </div>
    </div>


    <div class="layui-form-item" style="width: 100%;">
        <div class="form-group">
            <label for="size" class="control-label pr_no" style="width: 25%;float: left;text-align: right;padding: 9px 15px;">可获得奖励倍数</label>
            <div style="width: 70%;float: left;margin-left:initial;">
                <select class="form-control" id="awardMultiple" name="awardMultiple">
                    <option value="1" <#if taskScreenshot?? && taskScreenshot.awardMultiple?? && taskScreenshot.awardMultiple == 1>selected</#if>>1</option>
                    <option value="2" <#if taskScreenshot?? && taskScreenshot.awardMultiple?? && taskScreenshot.awardMultiple == 2>selected</#if>>2</option>
                    <option value="3" <#if taskScreenshot?? && taskScreenshot.awardMultiple?? && taskScreenshot.awardMultiple == 3>selected</#if>>3</option>
                    <option value="4" <#if taskScreenshot?? && taskScreenshot.awardMultiple?? && taskScreenshot.awardMultiple == 4>selected</#if>>4</option>
                    <option value="5" <#if taskScreenshot?? && taskScreenshot.awardMultiple?? && taskScreenshot.awardMultiple == 5>selected</#if>>5</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <div class="form-group">
            <label for="size" class="control-label pr_no" style="width: 25%;float: left;text-align: right;padding: 9px 15px;">失败可重做次数</label>
            <div style="width: 70%;float: left;margin-left:initial;">
                <select class="form-control" id="failTimes" name="failTimes">
                    <option value="0" <#if taskScreenshot?? && taskScreenshot.failTimes?? && taskScreenshot.failTimes == 0>selected</#if>>0</option>
                    <option value="1" <#if taskScreenshot?? && taskScreenshot.failTimes?? && taskScreenshot.failTimes == 1>selected</#if>>1</option>
                    <option value="2" <#if taskScreenshot?? && taskScreenshot.failTimes?? && taskScreenshot.failTimes == 2>selected</#if>>2</option>
                    <option value="3" <#if taskScreenshot?? && taskScreenshot.failTimes?? && taskScreenshot.failTimes == 3>selected</#if>>3</option>
                    <option value="4" <#if taskScreenshot?? && taskScreenshot.failTimes?? && taskScreenshot.failTimes == 4>selected</#if>>4</option>
                    <option value="5" <#if taskScreenshot?? && taskScreenshot.failTimes?? && taskScreenshot.failTimes == 5>selected</#if>>5</option>
                    <option value="9999" <#if taskScreenshot?? && taskScreenshot.failTimes?? && taskScreenshot.failTimes == 9999>selected</#if>>不限</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <div class="form-group">
            <label for="size" class="control-label pr_no" style="width: 25%;float: left;text-align: right;padding: 9px 15px;">任务分类</label>
            <div style="width: 70%;float: left;margin-left:initial;">
                <select class="form-control" id="taskCategoryId" name="taskCategoryId">
                    <#list taskClassifys as taskClassify>
                        <option value="${taskClassify.id}" <#if taskScreenshot?? && taskScreenshot.taskCategoryId??&&taskScreenshot.taskCategoryId == taskClassify.id>selected</#if>>${taskClassify.categoryName}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%">任务标签</label>
        <div  style="float: left;margin-left:initial;">
            <#list taskTags as taskTag>
                <input type="checkbox" name="taskTagId"  <#if tags?? && tags?seq_contains("${taskTag.id}")>checked</#if> value="${taskTag.id}" />${taskTag.tagName}
            </#list>
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%">任务简介</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="taskIntroduce"
                   placeholder="任务简介"
                   autocomplete="off" class="layui-input" value="${taskScreenshot.taskIntroduce!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%">分享简介</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="shareIntroduce"
                   placeholder="任务简介"
                   autocomplete="off" class="layui-input" value="${taskScreenshot.shareIntroduce!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <label class="layui-form-label" style="width: 25%">任务备注</label>
        <div class="layui-input-block" style="width: 70%;float: left;margin-left:initial;">
            <input type="text" name="taskRemarks"
                   placeholder="任务备注"
                   autocomplete="off" class="layui-input" value="${taskScreenshot.taskRemarks!''}">
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formUpdate">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<div class="col-xs-12" style="padding-left: 60px;margin-bottom: 50px;">
    <button type="button" id="add_btn" class="add_btn">添加步骤（图文）</button>
    <button type="button" id="add_btn2" class="add_btn">添加步骤（输入框：输入）</button>
    <button type="button" id="add_btn4" class="add_btn">添加步骤（图文:非上传图片）</button>

</div>

<div class="col-xs-12" style="padding: 0 40px 0 60px" id="_contents">

</div>

<script>

    //时间选择器
    $(document).ready(function () {
        laydate.render({
            elem: '#autoTime'
            ,type: 'time'
        });
        laydate.render({
            elem: '#autoOffTime'
            ,type: 'time'
        });
    });

    var es = [];

    var reg = /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d$/;

    var addImage = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var imgs = $("<div>").attr("id", "img" + index);
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(imgs).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "200px");
        var ctx = uploadify({
            container: '#img' + index
        });
        var step = {
            index: index,
            type: 'image',
            text: editor,
            image: ctx
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.image) {
                var images = [];
                images.push(content.image);
                ctx.setContent(images);
            }
            if (content.file) {
                var filess = [];
                filess.push(content.file);
                ctx.setContent(filess);
            }
        }
    };

    var addInput = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var input = $("<input>").attr("id", "input" + index).css({
            "width": "300px",
            "margin-top": "8px"
        });
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(input).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "160px");
        var step = {
            index: index,
            type: 'input',
            text: editor,
            input: input
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.input) {
                input.val(content.input);
            }
        }
    };
    var clock = false;
    var addExcel = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", index)
        var input = $("<input>").attr("type", "file").attr("id", "file");
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                clock = false;
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(input).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "80px");
        var step = {
            index: index,
            type: 'comment',
            text: editor,
            input: input
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.input) {
                input.val(content.input);
            }
        }
    };
    var addImageNoUp = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var imgs = $("<div>").attr("id", "img" + index);
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(imgs).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "200px");
        var ctx = uploadify({
            container: '#img' + index
        });
        var step = {
            index: index,
            type: 'imagenoup',
            text: editor,
            image: ctx
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.imagelist) {
                var images = [];
                for (var o = 0; o < content.imagelist.length; o++) {
                    images.push(content.imagelist[o])
                }

                ctx.setContent(images);
            }
            if (content.file) {
                var filess = [];
                filess.push(content.file);
                ctx.setContent(filess);
            }
        }
    };
    <#if item??>
    var steps = eval(${item.contents});
    if (steps.length > 0) {
        for (var i in steps) {
            if (steps[i].type == 'input') {
                addInput(steps[i]);
            }
            if (steps[i].type == 'image') {
                addImage(steps[i]);
            }
            if (steps[i].type == 'comment') {
                clock = true;
                addExcel();
            }
            if (steps[i].type == 'imagenoup') {

                addImageNoUp(steps[i]);
            }
        }
    }
    </#if>

    $(document).ready(function () {

        $("#add_btn").click(function () {
            addImage();
        });
        $("#add_btn2").click(function () {
            addInput();
        });
        $("#add_btn4").click(function () {
            clock = true;
            addImageNoUp();
        });
        layui.use('form', function () {

            var form = layui.form;
            form.render();
            form.on('submit(formUpdate)', function (data) {
                var items = [];

                if($("#autoTime").val()&&!reg.test($("#autoTime").val())){
                    alert("请输入XX:XX:XX格式的任务自动上架时间");
                    return false;
                }

                if($("#autoOffTime").val()&&!reg.test($("#autoOffTime").val())){
                    alert("请输入XX:XX:XX格式的任务自动下架时间");
                    return false;
                }

                for (var i = 0; i < es.length; i++) {
                    if (es[i].type == 'input') {
                        var item = {
                            type: es[i].type,
                            text: es[i].text.txt.html(),
                            input: es[i].input.val()
                        };
                        items.push(item);
                    }
                    if (es[i].type == 'image') {
                        var item = {
                            type: es[i].type,
                            text: es[i].text.txt.html(),
                            image: es[i].image.images()[0]
                        };
                        console.log(es[i].image.images()[0]);
                        items.push(item);
                    }
                    if (es[i].type == 'comment') {
                        var item = {
                            type: es[i].type,
                            text: ''
                        };
                        items.push(item);
                    }
                    if (es[i].type == 'imagenoup') {
                        var imglist = new Array();
                        for (var o = 0; o < es[i].image.images().length; o++) {
                            imglist.push(es[i].image.images()[o])
                        }

                        var item = {
                            type: es[i].type,
                            text: es[i].text.txt.html(),
                            imagelist: imglist
                        };
                        console.log(es[i].image.images()[0]);
                        items.push(item);
                    }
                }
                var contents = JSON.stringify(items);
                data.field.contents = contents;
                var tagList='';
                $("input[name='taskTagId']:checked").each(function(){
                    if(tagList==''){
                        tagList=$(this).val();
                    }else{
                        tagList=tagList+','+$(this).val();
                    }

                });
                data.field.taskTagIds = tagList;
                $.ajax({
                    url: "/sys/comments/edit",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data: data.field,    //参数值,键值对
                    type: "post",   //请求方式
                    beforeSend: function () {
                        //请求前的处理
                    },
                    success: function (req) {
                        //请求成功时处理
                        if (req.success) {
                            parent.showmsg(req.message);
                            parent.search();
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭

                        } else {
                            layer.msg(req.message)
                        }
                    },
                    complete: function () {
                        //请求完成的处理
                    },
                    error: function () {
                        //请求出错处理
                        layer.msg("请重试！若在失败请联系管理员")
                    }
                });

                return false;
            });
        });
    });

</script>
</body>
</html>